From e6ccc97166eb00f1b57c5b09b2fbd0b226740ebc Mon Sep 17 00:00:00 2001 From: oliskoli Date: Sat, 2 Dec 2006 20:37:13 +0000 Subject: [PATCH] Add option "DATUM" to xcsv format. --- csv_util.c | 22 ++++++++++++++++++---- csv_util.h | 4 +++- xcsv.c | 20 +++++++++++++++++++- xmldoc/chapters/styles.xml | 9 +++++++++ xmldoc/formats/options/xcsv-datum.xml | 4 ++++ 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 xmldoc/formats/options/xcsv-datum.xml diff --git a/csv_util.c b/csv_util.c index b92ebeb13..c08287475 100644 --- a/csv_util.c +++ b/csv_util.c @@ -25,6 +25,7 @@ #include "csv_util.h" #include "grtcirc.h" #include "strptime.h" +#include "jeeps/gpsmath.h" #define MYNAME "CSV_UTIL" @@ -38,6 +39,7 @@ #define EXCEL_TO_TIMET(a) ((a - 25569.0) * 86400.0) #define TIMET_TO_EXCEL(a) ((a / 86400.0) + 25569.0) +#define GPS_DATUM_WGS84 118 /****************************************************************************/ /* obligatory global struct */ @@ -583,6 +585,7 @@ xcsv_file_init(void) xcsv_file.type = ff_type_file; xcsv_file.mkshort_handle = mkshort_new_handle(); + xcsv_file.gps_datum = GPS_DATUM_WGS84; } /*****************************************************************************/ @@ -1055,6 +1058,11 @@ xcsv_data_read(void) s = csv_lineparse(NULL, xcsv_file.field_delimiter, "", linecount); } + if ((xcsv_file.gps_datum > -1) && (xcsv_file.gps_datum != GPS_DATUM_WGS84)) { + double alt; + GPS_Math_Known_Datum_To_WGS84_M(wpt_tmp->latitude, wpt_tmp->longitude, 0.0, + &wpt_tmp->latitude, &wpt_tmp->longitude, &alt, xcsv_file.gps_datum); + } waypt_add(wpt_tmp); } @@ -1084,13 +1092,14 @@ xcsv_waypt_pr(const waypoint *wpt) int i; field_map_t *fmp; queue *elem, *tmp; + double latitude, longitude; if ( oldlon < 900 ) { pathdist += radtomiles(gcdist(RAD(oldlat),RAD(oldlon), RAD(wpt->latitude),RAD(wpt->longitude))); } - oldlon = wpt->longitude; - oldlat = wpt->latitude; + longitude = oldlon = wpt->longitude; + latitude = oldlat = wpt->latitude; if (xcsv_file.field_delimiter && strcmp(xcsv_file.field_delimiter, "\\w") == 0) write_delimiter = " "; @@ -1130,12 +1139,17 @@ xcsv_waypt_pr(const waypoint *wpt) description = xstrdup(odesc); xfree(odesc); } + if ((xcsv_file.gps_datum > -1) && (xcsv_file.gps_datum != GPS_DATUM_WGS84)) { + double alt; + GPS_Math_WGS84_To_Known_Datum_M(latitude, longitude, 0.0, + &latitude, &longitude, &alt, xcsv_file.gps_datum); + } i = 0; QUEUE_FOR_EACH(xcsv_file.ofield, elem, tmp) { char *obuff; - double lat = wpt->latitude; - double lon = wpt->longitude; + double lat = latitude; + double lon = longitude; /* * A klunky concept. This should evaluate to true for any * field if we think we don't have realistic value for it. diff --git a/csv_util.h b/csv_util.h index 8da2d3e2a..cfb0eaaa2 100644 --- a/csv_util.h +++ b/csv_util.h @@ -131,7 +131,9 @@ typedef struct { short_handle mkshort_handle;/* handle for mkshort() */ ff_type type; /* format type for GUI wrappers. */ - + + int gps_datum; /* result of GPS_Lookup_Datum_Index */ + } xcsv_file_t; diff --git a/xcsv.c b/xcsv.c index 6c246c4c5..87cb0ead5 100644 --- a/xcsv.c +++ b/xcsv.c @@ -26,6 +26,7 @@ #include #include "defs.h" #include "csv_util.h" +#include "jeeps/gpsmath.h" #if CSVFMTS_ENABLED #define MYNAME "XCSV" @@ -38,6 +39,7 @@ static char *snupperopt = NULL; static char *snuniqueopt = NULL; char *prefer_shortnames = NULL; char *xcsv_urlbase = NULL; +static char *opt_datum; static const char *intstylebuf = NULL; @@ -58,6 +60,8 @@ arglist_t xcsv_args[] = { {"prefer_shortnames", &prefer_shortnames, "Use shortname instead of description", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, + {"datum", &opt_datum, "GPS datum (def. WGS 84)", + NULL, ARGTYPE_STRING, ARG_NOMINMAX}, ARG_TERMINATOR }; @@ -327,6 +331,13 @@ xcsv_parse_style_line(const char *sbuff) cet_convert_init(p, 1); xfree(p); } else + + if (ISSTOKEN(sbuff, "DATUM")) { + p = csv_stringtrim(&sbuff[8], "\"", 1); + xcsv_file.gps_datum = GPS_Lookup_Datum_Index(p); + is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", p); + xfree(p); + } else if (ISSTOKEN(sbuff, "IFIELD")) { key = val = pfc = NULL; @@ -515,6 +526,10 @@ xcsv_rd_init(const char *fname) } xcsv_file.xcsvfp = gbfopen(fname, "r", MYNAME); + if (opt_datum) { + xcsv_file.gps_datum = GPS_Lookup_Datum_Index(opt_datum); + is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", opt_datum); + } } @@ -564,7 +579,10 @@ xcsv_wr_init(const char *fname) setshort_badchars(xcsv_file.mkshort_handle, xcsv_file.badchars); } - + if (opt_datum) { + xcsv_file.gps_datum = GPS_Lookup_Datum_Index(opt_datum); + is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", opt_datum); + } } static void diff --git a/xmldoc/chapters/styles.xml b/xmldoc/chapters/styles.xml index e471f74c7..c4019f9a6 100644 --- a/xmldoc/chapters/styles.xml +++ b/xmldoc/chapters/styles.xml @@ -210,6 +210,15 @@ must be one listed by 'gpsbabel -l'. example: ENCODING UTF-8 # Use UTF-8 for input and output. +
+DATUM + +This value specifies the GPS datum to be used on read or write. Valid values for this +option are listed in . + + DATUM European 1950 + +
diff --git a/xmldoc/formats/options/xcsv-datum.xml b/xmldoc/formats/options/xcsv-datum.xml new file mode 100644 index 000000000..26519942f --- /dev/null +++ b/xmldoc/formats/options/xcsv-datum.xml @@ -0,0 +1,4 @@ + +This option specifies the GPS datum to be used on read or write. Valid values for this +option are listed in . + -- 2.30.2